﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace LL.Common
{
    /// <summary>
    /// 查询结果
    /// </summary>
    public class LoadDataResponse
    {

        /// <summary>
        /// 对应的请求
        /// </summary>
        public LoadDataRequest Request { get; set; }

        /// <summary>
        /// 返回数据列表
        /// </summary>
        public IEnumerable Data { get; set; }

        /// <summary>
        /// 返回分页前总行数（分页时有效）
        /// </summary>
        public int TotalRows;

        /// <summary>
        /// 当前返回第一条数据序号（分页时有效）
        /// </summary>
        public int StartRecordIndex { get; set; }

        /// <summary>
        /// 是否经过分页
        /// </summary>
        public bool IsPaged { get; set; }
    }

    /// <summary>
    /// 查询结果
    /// </summary>
    /// <typeparam name="T">返回的数据类型</typeparam>
    public class LoadDataResponse<T>
    {
        public LoadDataResponse()
        {
            
        }

        public LoadDataResponse(LoadDataRequest req)
        {
            Guard.NotNull(req);
            this.Request = req;
        }

        /// <summary>
        /// 对应的请求
        /// </summary>
        public LoadDataRequest Request { get; set; }

        /// <summary>
        /// 返回数据列表
        /// </summary>
        public IEnumerable<T> Data { get; set; }

        /// <summary>
        /// 返回分页前总行数（分页时有效）
        /// </summary>
        public int TotalRows;

        /// <summary>
        /// 当前返回最后一条数据序号（分页时有效）
        /// </summary>
        public int StartRecordIndex { get; set; }

        /// <summary>
        /// 是否经过分页
        /// </summary>
        public bool IsPaged { get; set; }

        //LoadDataResponse<T> => LoadDataResponse
        public static implicit operator LoadDataResponse(LoadDataResponse<T> value)
        {
            return new LoadDataResponse()
            {
                Request = value.Request,
                Data = (IEnumerable)value.Data,
                StartRecordIndex = value.StartRecordIndex,
                TotalRows = value.TotalRows
            };
        }

    }
}